package org.flexthinker.binding.ui.form.binding.flex
{
    import mx.utils.StringUtil;

    import org.flexthinker.binding.bean.UpdateStrategy;

    import org.flexthinker.binding.ui.form.binding.support.FieldBinder;

    import spark.components.supportClasses.ToggleButtonBase;

    /**
     * Binder implementation for all visual components extending <code>ToggleButtonBase</code>,
     * which expose a <code>selected</code> property.
     * These components are: <code>CheckBox</code>, <code>RadioButton</code>, <code>ToggleButton</code>.
     *
     * <code>DefaultFlexBinderFactory</code> automatically serves this
     * <code>ToggleButtonBaseBinder</code> for these components.
     *
     *  <code>ToggleButtonBaseBinder</code> generates a <code>Binding</code> on the <code>selected</code> property of the
     *  </code>component</code>. The <code>UpdateStrategy</code> is <code>READ_WRITE</code>.
     */
    public class ToggleButtonBaseBinder extends FieldBinder
    {
        public function ToggleButtonBaseBinder(component:ToggleButtonBase, formProperty:String)
        {
            super(component, formProperty);
            if ( !component.hasOwnProperty("selected"))
            {
                throw new ArgumentError( StringUtil.substitute( "Could not use ToggleButtonBaseBinder on {0}", component) );
            }

            super.componentProperty = "selected";
            super.updateStrategy = UpdateStrategy.READ_WRITE;
        }
    }
}
